package jdbc10_18;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Scanner;


public class Test_3 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        try {
            Class<?> aClass = Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url="jdbc:mysql://localhost:3306/jv75";
        Connection root=null;
        PreparedStatement ps=null;
        try {
             root = DriverManager.getConnection(url, "root", "123456");
             String sql="insert into s_student(sname,sex,telephone,qq,wechat,gradeid,enterdate,fromcity,birthday,address,pass) values (?,?,?,?,?,?,?,?,?,?,?)";
            ps = root.prepareStatement(sql);
            System.out.println("请输入学生姓名");
           ps.setString(1,in.next());
            System.out.println("请输入学生性别");
            ps.setString(2,in.next());
            System.out.println("请输入学生电话号码");
            ps.setString(3,in.next());
            System.out.println("请输入qq号");
            ps.setString(4,in.next());
            System.out.println("请输入微信号");
            ps.setString(5,in.next());
            System.out.println("请输入班级号");
            ps.setInt(6,in.nextInt());
            System.out.println("请输入学生入学时间");
            ps.setDate(7,Date.valueOf(in.next()));
            System.out.println("请输入城市名");
            ps.setString(8,in.next());
            System.out.println("请输入生日");
            ps.setDate(9,Date.valueOf(in.next()));
            System.out.println("请输入地址");
            ps.setString(10,in.next());
            System.out.println("请输入密码");
            ps.setString(11,in.next());
            ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (ps!=null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                if (root!=null) {
                    try {
                        root.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
